package com.msmall.community.play.cases.service.impl;

import java.util.Date;

import com.msmall.base.service.impl.BaseManagerImpl;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.play.cases.dao.CasesDao;
import com.msmall.community.play.cases.model.Cases;
import com.msmall.community.play.cases.service.CasesManager;
import com.msmall.community.user.service.UserManager;

public class CasesManagerImpl extends BaseManagerImpl<Cases, Long> implements CasesManager{

	private CasesDao casesDao;

	private UserManager userManager;
	
	public void setCasesDao(CasesDao casesDao) {
		this.casesDao = casesDao;
	}

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	public void saveCases(Cases cases, Long userid) {

		if(cases.getCasesId() != null && cases.getCasesId().longValue() != 0){
			if(cases.getAudit().compareTo(ConstantDB.AUDIT_PASS) != 0){
				cases.setEnabled(ConstantDB.UNAVALIABLE);
			}
		}
		if(cases.getLimits() == null||cases.getLimits() <= 0){
			cases.setLimits(ConstantDB.CASES_LIMITS_UNLIMIT);
		}
		cases.setCreator(userid);
		cases.setModifyTime(new Date());
		casesDao.saveObject(cases);
	}
	
	
}
